﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action.Protoss
{
	public class ActionProduceArchon : ActionProduceProtoss
	{
		public static ActionProduceArchon Instance = new ActionProduceArchon();
		private ActionProduceArchon() : base(12, 0, 0, 0) { }
		public override int AvailableProducer(State.IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			return (state.DarkTemplar + state.HighTemplar) / 2;
		}

		public override bool HaveTechnology(State.IBuildOrder bo) { return true; }
		public override bool IsInvalid(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			return base.IsInvalid(bo) || (state.DarkTemplar + state.HighTemplar + state.DarkTemplarProducing + state.HighTemplarProducing) < 2;
		}
		public override void Execute(IBuildOrder bo)
		{
			ProtossState state = bo.State as ProtossState;
			base.Execute(bo);
			int dt = state.DarkTemplar;
			int ht = state.HighTemplar;
			if (dt >= 2) state.DarkTemplar -= 2;
			else if (ht >= 2) state.HighTemplar -= 2;
			else
			{
				state.DarkTemplar--;
				state.HighTemplar--;
			}
			bo.AddAction(state.Time + BuildTime, new ActionGeneric("ActionSpawnArchon", (ActionGeneric.ActionExecuteDelegate)delegate(IBuildOrder ibo)
			{
				ProtossState ibostate = ibo.State as ProtossState;
				state.Archon++;
			}));
		}
		private IAction[,] m_Requirements;
		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionProduceTwilightCouncil.Instance } };
				return m_Requirements;
			}
		}
		private IAction[,] m_Inputs;
		public override IAction[,] Inputs
		{
			get
			{
				if (m_Inputs == null)
					m_Inputs = new IAction[,] { 
						{ ActionProduceDarkTemplar.Instance, ActionProduceDarkTemplar.Instance },
						{ ActionProduceDarkTemplar.Instance, ActionProduceHighTemplar.Instance },
						{ ActionProduceHighTemplar.Instance, ActionProduceHighTemplar.Instance }
					};
				return m_Inputs;
			}
		}
	}
}
